import axios from 'axios'

const request = axios.create({
  baseURL: 'http://127.0.0.1',
  timeout: 5000
})

// 请求拦截器
request.interceptors.request.use(function (config) {
  config.headers.authorization = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjU3MzMxNzkyLCJleHAiOjE2NTczMzUzOTJ9.CUqKkOxmSXcNzirpf9WAJZozGn1l9OADIK3cKfRRiMk"
  return config
}, function (error) {
  return Promise.reject(error)
})

// 响应拦截器
request.interceptors.response.use(function (res) {
  const {
    data
  } = res
  if (data.code !== 1000) {
    return Promise.reject(data)
  }
  return data.data
}, function (error) {
  return Promise.reject(error)
})

export default request